﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.DepartMentCommand;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.SheepCommandHandler;
using MediatR;
using System.ComponentModel.Design;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.DepartMentCommandHandler
{
    public class DepartMentCreateCommandHandler : IRequestHandler<DepartMentCreateCommand, Results<int>>
    {


        private readonly IDepartMentService departService;
        private readonly ILogger<DepartMentCreateCommandHandler> logger;
        public DepartMentCreateCommandHandler(IDepartMentService departService, ILogger<DepartMentCreateCommandHandler> logger)
        {
            this.departService = departService;
            this.logger = logger;
        }

        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(DepartMentCreateCommand request, CancellationToken cancellationToken)
        {
            var entity = new Department()
            {
                DepartId = request.DepartId,
                DepartName = request.DepartName,
                DepartLevel = request.DepartLevel,
                DepartState = request.DepartState,
                DepartTypeId = request.DepartTypeId,
                CreateName = request.CreateName,
                CreateTime = DateTime.Now,
                Isdelete = 0,
                Pid = request.Pid,
                UpdateName = request.UpdateName,
                UpdateTime = DateTime.Now,

            };

            var list = await departService.Add(entity);

            return Results<int>.DataResult(list);
        }


    }




}
